package com.example.lib_base.net

import com.example.lib_base.entity.AddCartEntity
import com.example.lib_base.entity.AddressEditEntity
import com.example.lib_base.entity.AddressEntity
import com.example.lib_base.entity.CartEntity
import com.example.lib_base.entity.CategoryEntity
import com.example.lib_base.entity.CommentEntity
import com.example.lib_base.entity.CouponEntity
import com.example.lib_base.entity.CreateOrderEntity
import com.example.lib_base.entity.DetailEntity
import com.example.lib_base.entity.IndexEntity
import com.example.lib_base.entity.LoginEntity
import com.example.lib_base.entity.OrderEntity
import com.example.lib_base.entity.PayEntity
import com.example.lib_base.entity.ProductEntity
import com.example.lib_base.entity.Res
import com.example.lib_base.entity.SendCodeEntity
import com.example.lib_base.entity.UserInfoEntity
import com.example.lib_base.param.AddressEdit
import com.example.lib_base.param.Comment
import com.example.lib_base.param.CreateOrder
import com.example.lib_base.param.Pay
import com.example.lib_base.param.Refund
import com.example.lib_base.utils.Cons
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiService {
    @POST(Cons.LOGIN_URL)
    suspend fun login(@Body body: RequestBody): Res<LoginEntity>

    @POST(Cons.SEND_CODE_URL)
    suspend fun sendCode(@Query("phone") phone: String): Res<SendCodeEntity>

    @POST(Cons.LOGIN_CODE_URL)
    suspend fun loginCode(@Body body: RequestBody): Res<LoginEntity>

    @GET(Cons.USER_INFO_URL)
    suspend fun userInfo(): Res<UserInfoEntity>

    @POST(Cons.UPDATE_PWD_URL)
    suspend fun updatePwd(@Body body: RequestBody): Res<Boolean>

    @GET(Cons.PRODUCT_URL)
    suspend fun product(
        @Query("keyword") keyword: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<ProductEntity>

    @GET(Cons.INDEX_URL)
    suspend fun index(): Res<IndexEntity>

    @GET(Cons.INDEX_PRODUCT_URL)
    suspend fun indexProduct(
        @Path("type") type: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<ProductEntity>

    @GET(Cons.COUPON_URL)
    suspend fun coupon(
        @Query("limit") limit: String,
        @Query("page") page: String,
        @Query("type") type: String
    ): Res<CouponEntity>

    @POST(Cons.COUPON_RECEIVE_URL)
    suspend fun couponReceive(@Body body: RequestBody): Res<String?>

    @GET(Cons.ADDRESS_URL)
    suspend fun address(@Query("limit") limit: Int, @Query("page") page: Int): Res<AddressEntity>

    @POST(Cons.ADDRESS_EDIT_URL)
    suspend fun addressEdit(@Body addressEdit: AddressEdit): Res<AddressEditEntity>

    @GET(Cons.ADDRESS_DETAIL_URL)
    suspend fun addressDetail(@Path("id") id: Int): Res<AddressEditEntity>

    @GET(Cons.DETAIL_URL)
    suspend fun detail(@Path("id") id: Int, @Query("type") type: String): Res<DetailEntity>

    @POST(Cons.ADD_CART_URL)
    suspend fun addCart(@Body body: RequestBody): Res<AddCartEntity>

    @GET(Cons.CART_URL)
    suspend fun cart(
        @Query("isValid") isValid: String,
        @Query("limit") limit: String,
        @Query("page") page: String
    ): Res<CartEntity>

    @POST(Cons.CART_UPDATE_URL)
    suspend fun cartUpdate(@Query("id") id: Int, @Query("number") number: Int): Res<String?>

    @POST(Cons.CART_DELETE_URL)
    suspend fun cartDelete(@Query("ids") ids: Array<Int>): Res<String?>


    @GET(Cons.CATEGORY_URL)
    suspend fun category(): Res<CategoryEntity>

    @GET(Cons.PRODUCT_URL)
    suspend fun productCategory(
        @Query("cid") cid: Int,
        @Query("keyword") keyword: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<ProductEntity>

    @GET(Cons.COMMENT_URL)
    suspend fun comment(
        @Path("id") id: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int,
        @Query("type") type: String
    ): Res<CommentEntity>
    @GET(Cons.ORDER_URL)
    suspend fun order(
        @Query("type") type: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<OrderEntity>
    @POST(Cons.COMMENT_SEND_URL)
    suspend fun commentSend(@Body comment: Comment):Res<Boolean>
    @POST(Cons.ORDER_DELETE_URL)
    suspend fun orderDelete(@Query("id")id:Int):Res<String?>
    @POST(Cons.ORDER_REFUND_URL)
    suspend fun orderRefund(@Body refund: Refund):Res<Boolean>
    @POST(Cons.ORDER_CREATE_URL)
    suspend fun orderCreate(@Body createOrder: CreateOrder):Res<CreateOrderEntity>
    @POST(Cons.PAY_URL)
    suspend fun pay(@Body pay: Pay):Res<PayEntity>
}